package cn.yuanqiao.activiti.domain;

import cn.yuanqiao.common.core.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.activiti.api.task.model.Task;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricTaskInstance;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ActHistoryTaskDTO
        extends BaseEntity {

    private static final long serialVersionUID = 1L;

    private String id;

    private String name;

    private String status;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date createdDate;
    private String instanceName;
    private String instanceId;
    private String definitionKey;
    private String businessKey;
    private String attachmentLink;
    private String assignee;

    private String isAgree;

    private Date startTime;

    private Date endTime;
    private List<Map<String,Object>> archiveVariables;

    private Map<String,Object> processVariables;

    private Map<String,Object> otherVariables = new HashMap<>();

    public Map<String, Object> getOtherVariables() {
        return otherVariables;
    }

    public void setOtherVariables(Map<String, Object> otherVariables) {
        this.otherVariables = otherVariables;
    }

    public void setOtherVariables(String key,Object value) {
        this.otherVariables.put(key,value);
    }

    public ActHistoryTaskDTO() {
    }

    public String getIsAgree() {
        return isAgree;
    }

    public void setIsAgree(String isAgree) {
        this.isAgree = isAgree;
    }

    public ActHistoryTaskDTO(
            HistoricTaskInstance task,
            HistoricProcessInstance processInstance) {
        this.id = task.getId();
        this.name = processInstance.getName();
        this.status = Task.TaskStatus.COMPLETED.toString();
        this.createdDate = processInstance.getStartTime();
        this.instanceName = processInstance.getProcessDefinitionName();
        this.instanceId = processInstance.getId();
        this.definitionKey=processInstance.getProcessDefinitionKey();
        this.businessKey=processInstance.getBusinessKey();
        this.startTime = task.getStartTime();
        this.endTime = task.getEndTime();
        this.assignee = task.getAssignee();
    }

    public List<Map<String, Object>> getArchiveVariables() {
        return archiveVariables;
    }

    public void setArchiveVariables(List<Map<String, Object>> archiveVariables) {
        this.archiveVariables = archiveVariables;
    }

    public Map<String, Object> getProcessVariables() {
        return processVariables;
    }

    public void setProcessVariables(Map<String, Object> processVariables) {
        this.processVariables = processVariables;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getAttachmentLink() {
        return attachmentLink;
    }

    public void setAttachmentLink(String attachmentLink) {
        this.attachmentLink = attachmentLink;
    }


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getInstanceName() {
        return instanceName;
    }

    public void setInstanceName(String instanceName) {
        this.instanceName = instanceName;
    }

    public String getDefinitionKey() {
        return definitionKey;
    }

    public void setDefinitionKey(String definitionKey) {
        this.definitionKey = definitionKey;
    }

    public String getBusinessKey() {
        return businessKey;
    }

    public void setBusinessKey(String businessKey) {
        this.businessKey = businessKey;
    }

    public String getInstanceId() {
        return instanceId;
    }

    public void setInstanceId(String instanceId) {
        this.instanceId = instanceId;
    }

    public String getAssignee() {
        return assignee;
    }

    public void setAssignee(String assignee) {
        this.assignee = assignee;
    }
}
